home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / gridex / frmprodu.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1998-01-02  |  15.1 KB  |  470 lines

  1. VERSION 5.00
  2. Begin VB.Form frmProducts 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Products"
  5.    ClientHeight    =   5100
  6.    ClientLeft      =   900
  7.    ClientTop       =   1755
  8.    ClientWidth     =   6915
  9.    BeginProperty Font 
  10.       Name            =   "Tahoma"
  11.       Size            =   8.25
  12.       Charset         =   0
  13.       Weight          =   400
  14.       Underline       =   0   'False
  15.       Italic          =   0   'False
  16.       Strikethrough   =   0   'False
  17.    EndProperty
  18.    Icon            =   "frmProducts.frx":0000
  19.    LinkTopic       =   "Form1"
  20.    LockControls    =   -1  'True
  21.    MaxButton       =   0   'False
  22.    MinButton       =   0   'False
  23.    ScaleHeight     =   340
  24.    ScaleMode       =   3  'Pixel
  25.    ScaleWidth      =   461
  26.    Begin VB.CheckBox chkOnsale 
  27.       Alignment       =   1  'Right Justify
  28.       Caption         =   "On Sale:"
  29.       Height          =   255
  30.       Left            =   3900
  31.       TabIndex        =   11
  32.       Top             =   4050
  33.       Width           =   990
  34.    End
  35.    Begin VB.CheckBox chkDiscontinued 
  36.       Alignment       =   1  'Right Justify
  37.       Caption         =   "Discontinued:"
  38.       Height          =   255
  39.       Left            =   330
  40.       TabIndex        =   10
  41.       Top             =   4020
  42.       Width           =   1365
  43.    End
  44.    Begin VB.TextBox txtField 
  45.       Height          =   345
  46.       Index           =   3
  47.       Left            =   1470
  48.       TabIndex        =   5
  49.       Top             =   2415
  50.       Width           =   4830
  51.    End
  52.    Begin VB.CommandButton cmdSuplierList 
  53.       Caption         =   "..."
  54.       Height          =   285
  55.       Left            =   2640
  56.       TabIndex        =   3
  57.       TabStop         =   0   'False
  58.       Top             =   1650
  59.       Width           =   300
  60.    End
  61.    Begin VB.CommandButton cmdCancel 
  62.       Cancel          =   -1  'True
  63.       Caption         =   "Cancel"
  64.       Height          =   360
  65.       Left            =   3570
  66.       TabIndex        =   13
  67.       Top             =   4635
  68.       Width           =   1200
  69.    End
  70.    Begin VB.CommandButton cmdOK 
  71.       Caption         =   "OK"
  72.       Default         =   -1  'True
  73.       Height          =   360
  74.       Left            =   2265
  75.       TabIndex        =   12
  76.       Top             =   4635
  77.       Width           =   1200
  78.    End
  79.    Begin VB.ComboBox cboCategory 
  80.       Height          =   315
  81.       Left            =   1470
  82.       Style           =   2  'Dropdown List
  83.       TabIndex        =   4
  84.       Top             =   2025
  85.       Width           =   2625
  86.    End
  87.    Begin VB.TextBox txtField 
  88.       Height          =   345
  89.       Index           =   6
  90.       Left            =   4680
  91.       TabIndex        =   7
  92.       Top             =   2970
  93.       Width           =   1620
  94.    End
  95.    Begin VB.TextBox txtField 
  96.       Height          =   345
  97.       Index           =   8
  98.       Left            =   1470
  99.       TabIndex        =   8
  100.       Top             =   3495
  101.       Width           =   1620
  102.    End
  103.    Begin VB.TextBox txtField 
  104.       Height          =   345
  105.       Index           =   7
  106.       Left            =   4680
  107.       TabIndex        =   9
  108.       Top             =   3480
  109.       Width           =   1620
  110.    End
  111.    Begin VB.TextBox txtField 
  112.       Height          =   345
  113.       Index           =   5
  114.       Left            =   1470
  115.       TabIndex        =   6
  116.       Top             =   2985
  117.       Width           =   1620
  118.    End
  119.    Begin VB.TextBox txtField 
  120.       Height          =   345
  121.       Index           =   2
  122.       Left            =   1470
  123.       TabIndex        =   2
  124.       Top             =   1620
  125.       Width           =   1500
  126.    End
  127.    Begin VB.TextBox txtField 
  128.       Height          =   345
  129.       Index           =   1
  130.       Left            =   1470
  131.       TabIndex        =   1
  132.       Top             =   1215
  133.       Width           =   4815
  134.    End
  135.    Begin VB.TextBox txtField 
  136.       Height          =   345
  137.       Index           =   0
  138.       Left            =   1470
  139.       TabIndex        =   0
  140.       Top             =   795
  141.       Width           =   1485
  142.    End
  143.    Begin VB.Image Image1 
  144.       Height          =   480
  145.       Left            =   135
  146.       Picture         =   "frmProducts.frx":014A
  147.       Top             =   45
  148.       Width           =   480
  149.    End
  150.    Begin VB.Label lblName 
  151.       Alignment       =   1  'Right Justify
  152.       BackColor       =   &H80000003&
  153.       Caption         =   "Products "
  154.       BeginProperty Font 
  155.          Name            =   "Tahoma"
  156.          Size            =   18
  157.          Charset         =   0
  158.          Weight          =   700
  159.          Underline       =   0   'False
  160.          Italic          =   0   'False
  161.          Strikethrough   =   0   'False
  162.       EndProperty
  163.       ForeColor       =   &H8000000E&
  164.       Height          =   600
  165.       Left            =   -405
  166.       TabIndex        =   24
  167.       Top             =   0
  168.       Width           =   7350
  169.    End
  170.    Begin VB.Label lblField 
  171.       AutoSize        =   -1  'True
  172.       Caption         =   "Quantity per Unit:"
  173.       Height          =   195
  174.       Index           =   2
  175.       Left            =   45
  176.       TabIndex        =   23
  177.       Top             =   2490
  178.       Width           =   1305
  179.    End
  180.    Begin VB.Label lblSupplierName 
  181.       AutoSize        =   -1  'True
  182.       Height          =   195
  183.       Left            =   3150
  184.       TabIndex        =   22
  185.       Top             =   1695
  186.       Width           =   45
  187.    End
  188.    Begin VB.Line Line1 
  189.       BorderColor     =   &H80000014&
  190.       Index           =   1
  191.       X1              =   -25
  192.       X2              =   970
  193.       Y1              =   302
  194.       Y2              =   302
  195.    End
  196.    Begin VB.Line Line1 
  197.       BorderColor     =   &H80000010&
  198.       Index           =   0
  199.       X1              =   -25
  200.       X2              =   970
  201.       Y1              =   301
  202.       Y2              =   301
  203.    End
  204.    Begin VB.Label lblField 
  205.       AutoSize        =   -1  'True
  206.       Caption         =   "Reorder Level:"
  207.       Height          =   195
  208.       Index           =   9
  209.       Left            =   285
  210.       TabIndex        =   21
  211.       Top             =   3555
  212.       Width           =   1065
  213.    End
  214.    Begin VB.Label lblField 
  215.       AutoSize        =   -1  'True
  216.       Caption         =   "Category:"
  217.       Height          =   195
  218.       Index           =   8
  219.       Left            =   615
  220.       TabIndex        =   20
  221.       Top             =   2130
  222.       Width           =   735
  223.    End
  224.    Begin VB.Label lblField 
  225.       AutoSize        =   -1  'True
  226.       Caption         =   "Units on Order:"
  227.       Height          =   195
  228.       Index           =   7
  229.       Left            =   3435
  230.       TabIndex        =   19
  231.       Top             =   3555
  232.       Width           =   1110
  233.    End
  234.    Begin VB.Label lblField 
  235.       AutoSize        =   -1  'True
  236.       Caption         =   "Unit in Stock:"
  237.       Height          =   195
  238.       Index           =   6
  239.       Left            =   3600
  240.       TabIndex        =   18
  241.       Top             =   3000
  242.       Width           =   945
  243.    End
  244.    Begin VB.Label lblField 
  245.       AutoSize        =   -1  'True
  246.       Caption         =   "Unit Price:"
  247.       Height          =   195
  248.       Index           =   5
  249.       Left            =   615
  250.       TabIndex        =   17
  251.       Top             =   3000
  252.       Width           =   735
  253.    End
  254.    Begin VB.Label lblField 
  255.       AutoSize        =   -1  'True
  256.       Caption         =   "Supplier ID:"
  257.       Height          =   195
  258.       Index           =   3
  259.       Left            =   510
  260.       TabIndex        =   16
  261.       Top             =   1665
  262.       Width           =   840
  263.    End
  264.    Begin VB.Label lblField 
  265.       AutoSize        =   -1  'True
  266.       Caption         =   "Product Name:"
  267.       Height          =   195
  268.       Index           =   1
  269.       Left            =   285
  270.       TabIndex        =   15
  271.       Top             =   1275
  272.       Width           =   1065
  273.    End
  274.    Begin VB.Label lblField 
  275.       AutoSize        =   -1  'True
  276.       Caption         =   "Product ID:"
  277.       Height          =   195
  278.       Index           =   0
  279.       Left            =   525
  280.       TabIndex        =   14
  281.       Top             =   870
  282.       Width           =   825
  283.    End
  284. Attribute VB_Name = "frmProducts"
  285. Attribute VB_GlobalNameSpace = False
  286. Attribute VB_Creatable = False
  287. Attribute VB_PredeclaredId = True
  288. Attribute VB_Exposed = False
  289. Option Explicit
  290. Dim m_db As Database
  291. Dim mrstProducts As Recordset
  292. Dim mrstSuppliers As Recordset
  293. Dim mvarBookmark As Variant
  294. Dim mbIsNew As Boolean
  295. Public Key As String
  296. Private Const fldProductID = 0
  297. Private Const fldProductName = 1
  298. Private Const fldSupplierID = 2
  299. Private Const fldQuantityPerUnit = 3
  300. Private Const fldCategory = 4
  301. Private Const fldUnitPrice = 5
  302. Private Const fldUnitsInStock = 6
  303. Private Const fldUnitsOnOrder = 7
  304. Private Const fldReorderLevel = 8
  305. Private Const fldDiscontinued = 9
  306. Private Const fldOnSale = 10
  307. Dim m_DataChanged(10) As Boolean
  308. Public Sub EditRecord(db As Database, rs As Recordset)
  309. Dim rstCategory As Recordset
  310. Dim i As Long
  311. On Error Resume Next
  312.     Set m_db = db
  313.     Set mrstSuppliers = m_db.OpenRecordset("Suppliers", dbOpenTable)
  314.     Set mrstProducts = rs.Clone
  315.     mvarBookmark = rs.Bookmark
  316.     mrstProducts.Bookmark = mvarBookmark
  317.     Set rstCategory = m_db.OpenRecordset("SELECT Categories.CategoryID, Categories.CategoryName FROM Categories ORDER BY Categories.CategoryName", dbOpenSnapshot)
  318.     cboCategory.Clear
  319.     cboCategory.AddItem ""
  320.     Do Until rstCategory.EOF
  321.         cboCategory.AddItem rstCategory![CategoryName]
  322.         cboCategory.ItemData(cboCategory.NewIndex) = rstCategory![CategoryID]
  323.         rstCategory.MoveNext
  324.     Loop
  325.     txtField(fldProductID).Text = mrstProducts![ProductID]
  326.     txtField(fldProductName).Text = mrstProducts![ProductName]
  327.     txtField(fldSupplierID).Text = mrstProducts![SupplierID]
  328.     txtField(fldQuantityPerUnit).Text = mrstProducts![QuantityPerUnit]
  329.     txtField(fldUnitPrice).Text = mrstProducts![UnitPrice]
  330.     txtField(fldUnitsInStock).Text = mrstProducts![UnitsInStock]
  331.     txtField(fldUnitsOnOrder).Text = mrstProducts![UnitsOnOrder]
  332.     txtField(fldReorderLevel).Text = mrstProducts![ReorderLevel]
  333.     If IsNull(mrstProducts![CategoryID]) Then
  334.         cboCategory.ListIndex = 0
  335.     Else
  336.         For i = 1 To cboCategory.ListCount - 1
  337.             If cboCategory.ItemData(i) = mrstProducts![CategoryID] Then
  338.                 cboCategory.ListIndex = i
  339.                 Exit For
  340.             End If
  341.         Next
  342.     End If
  343.     If Not IsNull(mrstProducts![Discontinued]) Then
  344.         If mrstProducts![Discontinued] Then
  345.             chkDiscontinued.Value = vbChecked
  346.         Else
  347.             chkDiscontinued.Value = vbUnchecked
  348.         End If
  349.     Else
  350.         chkDiscontinued.Value = vbUnchecked
  351.     End If
  352.     If Not IsNull(mrstProducts![OnSale]) Then
  353.         If mrstProducts![OnSale] Then
  354.             chkOnsale.Value = vbChecked
  355.         Else
  356.             chkOnsale.Value = vbUnchecked
  357.         End If
  358.     Else
  359.         chkOnsale.Value = vbUnchecked
  360.     End If
  361.     Caption = "Products - " & mrstProducts![ProductName]
  362.     For i = 0 To UBound(m_DataChanged)
  363.         m_DataChanged(i) = False
  364.     Next
  365.     Me.Show
  366. End Sub
  367. Public Sub NewRecord(db As Database, rs As Recordset)
  368. Dim rstCategory As Recordset
  369. Dim i As Long
  370. On Error Resume Next
  371.     Set m_db = db
  372.     Set mrstSuppliers = m_db.OpenRecordset("Suppliers", dbOpenTable)
  373.     Set mrstProducts = rs.Clone
  374.     mbIsNew = True
  375.     mvarBookmark = Null
  376.     Set rstCategory = m_db.OpenRecordset("SELECT Categories.CategoryID, Categories.CategoryName FROM Categories ORDER BY Categories.CategoryName", dbOpenSnapshot)
  377.     cboCategory.Clear
  378.     cboCategory.AddItem ""
  379.     Do Until rstCategory.EOF
  380.         cboCategory.AddItem rstCategory![CategoryName]
  381.         cboCategory.ItemData(cboCategory.NewIndex) = rstCategory![CategoryID]
  382.         rstCategory.MoveNext
  383.     Loop
  384.     Caption = "Products - New Product"
  385.     Me.Show
  386. End Sub
  387. Private Sub cboCategory_Click()
  388.     m_DataChanged(fldCategory) = True
  389. End Sub
  390. Private Sub chkOnsale_Click()
  391.     m_DataChanged(fldOnSale) = True
  392. End Sub
  393. Private Sub cmdCancel_Click()
  394.     Unload Me
  395. End Sub
  396. Private Sub cmdOK_Click()
  397. On Error GoTo EH_cmdOK
  398. Dim bUpdate As Boolean
  399. Dim i As Integer
  400.     For i = 0 To UBound(m_DataChanged)
  401.         If m_DataChanged(i) Then bUpdate = True
  402.     Next
  403.     If bUpdate Then
  404.         If mbIsNew Then
  405.             mrstProducts.AddNew
  406.         Else
  407.             mrstProducts.Edit
  408.         End If
  409.         If m_DataChanged(fldProductID) Then mrstProducts![ProductID] = txtField(fldProductID)
  410.         If m_DataChanged(fldProductName) Then mrstProducts![ProductName] = txtField(fldProductName)
  411.         If m_DataChanged(fldSupplierID) Then mrstProducts![SupplierID] = txtField(fldSupplierID)
  412.         If m_DataChanged(fldQuantityPerUnit) Then mrstProducts![QuantityPerUnit] = txtField(fldQuantityPerUnit)
  413.         If m_DataChanged(fldUnitPrice) Then mrstProducts![UnitPrice] = txtField(fldUnitPrice)
  414.         If m_DataChanged(fldUnitsInStock) Then mrstProducts![UnitsInStock] = txtField(fldUnitsInStock)
  415.         If m_DataChanged(fldUnitsOnOrder) Then mrstProducts![UnitsOnOrder] = txtField(fldUnitsOnOrder)
  416.         If m_DataChanged(fldReorderLevel) Then mrstProducts![ReorderLevel] = txtField(fldReorderLevel)
  417.         If m_DataChanged(fldCategory) Then
  418.             If cboCategory.ListIndex <= 0 Then
  419.                 mrstProducts![CategoryID] = Null
  420.             Else
  421.                 mrstProducts![CategoryID] = cboCategory.ItemData(cboCategory.ListIndex)
  422.             End If
  423.         End If
  424.         If m_DataChanged(fldDiscontinued) Then mrstProducts![Discontinued] = (chkDiscontinued.Value = vbChecked)
  425.         If m_DataChanged(fldOnSale) Then mrstProducts![OnSale] = (chkOnsale.Value = vbChecked)
  426.         mrstProducts.Update
  427.         Hide
  428.         frmMain.OnRecordUpdate CatalogProducts, mvarBookmark
  429.     End If
  430.     Unload Me
  431.     Exit Sub
  432. EH_cmdOK:
  433.     MsgBox Err.Description
  434. End Sub
  435. Private Sub cmdSuplierList_Click()
  436. Dim varSup As Variant
  437.     varSup = frmList.ChooseSupplier(m_db.Name, txtField(fldSupplierID))
  438.     If Not IsNull(varSup) Then
  439.         txtField(fldSupplierID) = varSup
  440.     End If
  441.     txtField(fldSupplierID).SetFocus
  442. End Sub
  443. Private Sub chkDiscontinued_Click()
  444.     m_DataChanged(fldDiscontinued) = True
  445. End Sub
  446. Private Sub Form_Unload(Cancel As Integer)
  447.     frmMain.UnloadForm Key
  448. End Sub
  449. Private Sub txtField_Change(Index As Integer)
  450.     m_DataChanged(Index) = True
  451.     If Index = fldSupplierID Then
  452.         SearchSupplierName
  453.     End If
  454. End Sub
  455. Private Sub SearchSupplierName()
  456. Dim strSupplierID As String
  457.     strSupplierID = txtField(fldSupplierID)
  458.     If strSupplierID = "" Then
  459.         lblSupplierName = ""
  460.     Else
  461.         mrstSuppliers.Index = "PrimaryKey"
  462.         mrstSuppliers.Seek "=", strSupplierID
  463.         If mrstSuppliers.NoMatch Then
  464.             lblSupplierName = ""
  465.         Else
  466.             lblSupplierName = mrstSuppliers![CompanyName]
  467.         End If
  468.     End If
  469. End Sub
  470.